package com.just.gameapp.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.just.gameapp.entity.Account;
import com.just.gameapp.mapper.AccountMapper;
import com.just.gameapp.service.AccountService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @author zyr
 * @date 2024/6/18 下午2:58
 * @Description
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {
    @Resource
    private AccountMapper accountMapper;
    @Override
    public Object registerAccount(Account account) {
        LambdaQueryWrapper<Account> query =  new LambdaQueryWrapper<>();
        query.eq(Account::getAccountName,account.getAccountName());
        if(accountMapper.selectOne(query)!=null){
            return "用户已存在";
        }else{
            if(accountMapper.insert(account)==1){
                return null;
            }
            return "新增用户失败";
        }
    }

    @Override
    public Object loginAccount(Account account) {
        LambdaQueryWrapper<Account> query =new LambdaQueryWrapper<>();
        query.eq(Account::getAccountName,account.getAccountName())
                .eq(Account::getPassword,account.getPassword());
        // 如果查询到登录用户
        Account user = accountMapper.selectOne(query);
        if(user!=null){
            return user.getAccountId();
        }else{
            return "用户名或密码错误";
        }
    }
}
